package com.kky.pp.popup

import android.content.Context
import android.widget.ImageView
import android.widget.TextView
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter
import com.contrarywind.view.WheelView
import com.kky.pp.R
import razerdp.basepopup.BasePopupWindow

class SelectHeightPopu(var context: Context, var height: String?, var callback: OnCallBack) :
    BasePopupWindow(context) {
    init {
        setContentView(R.layout.popup_select_height)
        initView()
    }

    var position = 0
    private fun initView() {
        val dialogClose = findViewById<ImageView>(R.id.imgViewPopupSelectHeightClose)
        val bntSave = findViewById<TextView>(R.id.txtPopupSelectHeightSave)
        val wheelView = findViewById<WheelView>(R.id.wheelViewPopupSelectHeight)
        wheelView?.setLineSpacingMultiplier(2f)
        wheelView?.setItemsVisibleCount(5)
        wheelView?.setTypeface(context.resources.getFont(io.rong.imkit.R.font.intersemibold))
        wheelView?.setCyclic(true)
        wheelView?.setTextSize(20f)
        wheelView?.setTextColorCenter(context.getColor(R.color.white))
        wheelView?.setDividerColor(0xffff00)

        val wheelViewYearAdapter = ArrayWheelAdapter(getHeigt())
        wheelView?.adapter = wheelViewYearAdapter
        if (!height.isNullOrEmpty())
            position = getHeigt().indexOf(height)
        wheelView?.currentItem = position
        wheelView?.setOnItemSelectedListener { index ->
            position = index
        }

        dialogClose.setOnClickListener {
            dismiss()
        }
        bntSave.setOnClickListener {
            callback.callBack(wheelViewYearAdapter.getItem(position).toString())
            dismiss()
        }
        setOutSideDismiss(true)
    }

    interface OnCallBack {
        fun callBack(date: String)
    }

    var min = 7
    private fun getHeigt(): MutableList<String> {
        val heihts = arrayListOf<String>()
        for (index in 3..7) {
            for (k in (if (index == 3) 7 else 0)..11)
                heihts.add("$index'$k\"")
        }
        return heihts
    }
}